﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ToWaDBFirst.Models;

namespace ToWaDBFirst.Controllers
{
    /**
     * Controller to manage the listing of messages in the outbox and to view a specified message in detail.
     **/
    [Authorize]
    public class OutboxController : Controller
    {

        /**
         * Class objects to manage database and service operations.
         **/
        ToWaDBFirstDBEntities2 db = new ToWaDBFirstDBEntities2();
        ToWaService service = new ToWaService();

        /**
         * Method to list all the messages available to the logged in user.
         * Returns the View containing the messages.
         **/
        // GET: /Outbox/
        public ActionResult Index()
        {
            var user = db.users.Single(u => u.username == User.Identity.Name);
            return View(user.messages);
        }

        /**
         * Method to view a specified message in the details View.
         * Returns the message with the specified id.
         **/
        // GET: /Outbox/Details/
        public ActionResult Details(int id)
        {
            return View(service.InspectMessage(id));
        }
    }
}
